<template>
	<view class="tabbar-container">
		<block>
			<view class="tabbar-item" v-for="(item,index) in tabbarList"
                  :key="index"
				:class="[item.centerItem ? ' center-item' : '']" @click="changeItem(item)">
				<view class="item-top">
					<image :src="currentItem==item.id ? item.selectIcon : item.icon"></image>
				</view>
				<view class="item-bottom" :class="[currentItem==item.id ? 'item-active' : '']">
					<text>{{item.text}}</text>
				</view>
			</view>
		</block>
	</view>
</template>

<script setup>
	import {
		onMounted,
		readonly
	} from 'vue';
    import {getServerStatic} from "@/utils/tool";
    import {Config} from "@/common/config";
	const props = defineProps({
		currentPage: {
			type: Number,
			default: 0
		}
	})
	const currentItem = ref(0)

	onMounted(() => {
		currentItem.value = props.currentPage
		// #ifdef MP-WEIXIN
		uni.hideTabBar();
		// #endif
	})

	const tabbarList = readonly([{
		id: 0,
		path: "/pages/index/index",
		// icon: getServerStatic("/static/tabbar/index.png"),
		// selectIcon: getServerStatic("/static/tabbar/index-select.png"),
        icon: Config.MINI_STATIC_HOST + "/static/tabbar/index.png",
        selectIcon: Config.MINI_STATIC_HOST + "/static/tabbar/index-select.png",
		text: "首页",
		centerItem: false
	}, {
		id: 1,
		path: "/pages/hospital/hospital",
		// icon: getServerStatic("/static/tabbar/center-select.png"),
		// selectIcon: getServerStatic("/static/tabbar/center-select.png"),
        icon: Config.MINI_STATIC_HOST + "/static/tabbar/center-select.png",
        selectIcon: Config.MINI_STATIC_HOST + "/static/tabbar/center-select.png",
		text: "济世堂",
		centerItem: true
	}, {
		id: 2,
		path: "/pages/mine/mine",
		// icon: getServerStatic("/static/tabbar/mine.png"),
		// selectIcon: getServerStatic("/static/tabbar/mine-select.png"),
        icon: Config.MINI_STATIC_HOST + "/static/tabbar/mine.png",
        selectIcon: Config.MINI_STATIC_HOST + "/static/tabbar/mine-select.png",
		text: "我的",
		centerItem: false
	}])
	const changeItem = item => {
		uni.switchTab({
			url: item.path
		});
	}
</script>

<style lang="scss" scoped>
	view {
		padding: 0;
		margin: 0;
		box-sizing: border-box;
	}

	.tabbar-container {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 110rpx;
		/* box-shadow: 0 0 5px #999;  */
		box-shadow: 0px 3px 20px rgba(0, 0, 0, 0.16);
		border-top: 1px;
		display: flex;
		align-items: center;
		padding: 5rpx 0;
		color: #999999;
		z-index: 200;
		background-color: #fff;
	}

	.tabbar-container .tabbar-item {
		flex: 1;
		height: 100rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		text-align: center;
	}

	.tabbar-container .item-active {
		color: #9FA9BB;
	}

	.tabbar-container .center-item {
		display: block;
		position: relative;
	}

	.tabbar-container .tabbar-item .item-top {
		width: 54rpx;
		height: 54rpx;
		padding: 0rpx;
	}

	.tabbar-container .center-item .item-top {
		flex-shrink: 0;
		width: 100rpx;
		height: 100rpx;
		position: absolute;
		top: -50rpx;
		left: calc(50% - 50rpx);
		border-radius: 50%;
		box-shadow: 0px 3px 20px rgba(0, 0, 0, 0.16);
		/* box-shadow: 0 0 5px #999;  */
		background-color: #ffffff;
		padding: 10rpx;
	}

	.tabbar-container .tabbar-item .item-top image {
		width: 100%;
		height: 100%;
	}

	.tabbar-container .tabbar-item:nth-child(3) .item-top image {
		// background: #ff0000;
	}

	.tabbar-container .tabbar-item .item-bottom {
		font-size: 28rpx;
		width: 100%;
	}

	.tabbar-container .center-item .item-bottom {
		position: absolute;
		bottom: 5rpx;
	}
</style>
